package com.example.home.attorney.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.attorney.activity.MeConsultDateil;
import com.example.home.attorney.bean.MeConsultBean;
import com.google.gson.Gson;

import java.util.List;

public class MeConsultAdapter extends RecyclerView.Adapter<MeConsultAdapter.MyHoldy> {
    private Context context;
    private List<MeConsultBean.RowsBean> list;

    public MeConsultAdapter(Context context, List<MeConsultBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MeConsultAdapter.MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_mecon, null);
        return new MeConsultAdapter.MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MeConsultAdapter.MyHoldy holder, int position) {
        holder.lawyerName.setText(list.get(position).getLawyerName());
        holder.legalExpertiseName.setText(list.get(position).getLegalExpertiseName());
        String state = list.get(position).getState();
        if ("0".equals(state)){
            holder.state.setText("未受理");
        }else if ("1".equals(state)){
            holder.state.setText("已受理");
        }
        holder.createTime.setText(list.get(position).getCreateTime());
        holder.btnZixun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, MeConsultDateil.class);
                Gson gson = new Gson();
                intent.putExtra("meconsultD",gson.toJson(list.get(position)));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        private ImageView txImg;
        private TextView lawyerName;
        private TextView legalExpertiseName;
        private TextView state;
        private TextView createTime;
        private Button btnZixun;

        public MyHoldy(@NonNull View itemView) {
            super(itemView);

            txImg = itemView.findViewById(R.id.tx_img);
            lawyerName = itemView.findViewById(R.id.lawyerName);
            legalExpertiseName = itemView.findViewById(R.id.legalExpertiseName);
            state = itemView.findViewById(R.id.state);
            createTime = itemView.findViewById(R.id.createTime);
            btnZixun = itemView.findViewById(R.id.btn_zixun);

        }
    }
}
